
#include "DeSerializer.h"
#include "Common/Errors.h"

using namespace ttg;
using namespace ttg::extras::serialization;

//--------------------
//--- DeSerializer ---
//--------------------

void DeSerializer::deserializeString(std::string &value, const char *name)
{
	int len;
	deserializeInt(len, name);
	if (len < 0)
		value = "";
	else
	{
		value.resize(len);
		deserializeMemory(const_cast<char *>(value.c_str()), len, name);
	}
}

bool DeSerializer::deserializeObject(structures::SerializableObject &object, const char *name)
{
	//Loading.
	bool is_null;
	deserializeReferenceStart(is_null, name);
	if (!is_null)
		object.deserialize(*this);
	deserializeReferenceEnd(name);
	return !is_null;
}
